package jfuzzyprincepless.zarchive.puntaelenaexperiments;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import laboratoryQ.computation.flatness.DiagramData;
import laboratoryQ.experiment.IExperimentResult;
import laboratoryQ.experiment.reportage.ui.diagram2component.IDiagramsExtractor;
import laboratoryQ.experiment.reportage.ui.diagram2component.ITitlesExtractor;

public class FacilitiesDiagramExtractorA implements IDiagramsExtractor, ITitlesExtractor {
	@Override
	public List<DiagramData[]> extractDiagrams(IExperimentResult expResult) {
		GrSzExperimentContext context = (GrSzExperimentContext) expResult;
		FGraphSzDepCompareFactor3vsTrivialExSettings settings = context.getExperimentSettings();
		List<DiagramData[]> result = new ArrayList<DiagramData[]>();

		if (context.graphSizeCosts != null) {
			addDiagram(
				context.graphSizeCosts,
				settings.citiesCountBeg,
				settings.citiesCountEnd,
				result
			);
		}

		if (context.diffAgainstAdv != null) {
			addDiagram(
				context.diffAgainstAdv,
				settings.citiesCountBeg,
				settings.citiesCountEnd,
				result
			);
		}

		return result;
	}

	@Override
	public List<String> getTitles(IExperimentResult expResult) {
		return Arrays.asList("A", "diff adv");
	}

	@Override
	public List<String> getXCaptions(IExperimentResult expResult) {
		return Arrays.asList(
			"X",
			"X"
		);
	}

	@Override
	public List<String> getYCaptions(IExperimentResult expResult) {
		return Arrays.asList(
			"Y",
			"Y"
		);
	}

	private void addDiagram(
		List<double[]> diaSrc,
		int citiesCountBeg,
		int citiesCountEnd,
		List<DiagramData[]> result
	) {
		int count = citiesCountEnd - citiesCountBeg + 1;
		double[] xs = new double[count];
		for (int i = 0; i < count; i++) {
			xs[i] = citiesCountBeg + i;
		}
		DiagramData[] dia = new DiagramData[diaSrc.size()];
		for (int i = 0; i < dia.length; i++) {
			dia[i] = new DiagramData(xs, diaSrc.get(i));
		}
		result.add(dia);
	}
}
